<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="${pageContext.request.contextPath}" var="ctx" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>特权列表</title>
<link href="${ctx}/css/skin.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/page.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/backOffice.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.myPagination.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		page(1);
	});
	function page(pageIndex) {
		$("#demo1").myPagination({
			currPage : pageIndex,
			ajax : {
				on : true,
				dataType : 'json',
				url : '${ctx}/privilege/post',
				callback : 'showData',
				param : {
					on : true,
					type : 'all',
				}
			}
		});
	}
	
	function showData(data) {
		var rows = data.data.rows;
		var str = '';
		for ( var i = 0; i < rows.length; i++) {
			str += '<tr>';
			str += '<td height="30" class="left_txt2" align="middle">'
					+ ((currPage - 1) * 10 + (i + 1)) + '</td>';
			str += '<td height="30" class="left_txt2" align="middle">'
				+ rows[i].privName + '</td>';
				str += '<td height="30" class="left_txt2" align="middle">'
					+ rows[i].privUrl + '</td>';
			str += '</tr>';
		}
		$('#staffs').html('').html(str);
	}
	
	function queryModules(){
		$.ajax({
			url : '${ctx}/module/post',
			type : 'post',
			data : {type:'all'},
			dataType : 'json',
			success : function(data){
				if(data.status == 200){
					str = "";
					var models = data.data;
					for(var i=0;i<models.length;i++){
						str += '<option value="'+models[i].modId+'">'+models[i].modName+'</option>'
					}
					$('#models').html('').html(str);
					$('#addDiv').show();
				}
				
			}
		});
	}
	
	function addrivileges(){
		var rivilegesName = $.trim($('#rivilegesName').val());
		if(rivilegesName == ''){
			$.msgbox.show({
				message : '特权名不能为空',
				icon : 'no'
			});
			return;
		}
		var modId = $('#models').select().val();
		if(modId == ''){
			$.msgbox.show({
				message : '模块不能为空',
				icon : 'no'
			});
			return;
		}
		var privUrl = $('#privUrl').select().val();
		if(privUrl == ''){
			$.msgbox.show({
				message : '特权URL不能为空',
				icon : 'no'
			});
			return;
		}
		var isTree = $('#isTree').is(":checked")==true?1:0;
		var obj = {};
		obj.type ='add';
		obj.privName = rivilegesName;
		obj.modId = modId;
		obj.privUrl = privUrl;
		obj.isTree = isTree;
		$.ajax({
			url : '${ctx}/privilege/post',
			type : 'post',
			data : obj,
			dataType : 'json',
			success : function(data){
				if(data.status == 200){
					$.msgbox.show({
						message : '添加成功',
						icon : 'ok'
					});
				}else{
					$.msgbox.show({
						message : data.text,
						icon : 'no'
					});
				}
			}
		});
	}
</script>
</head>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" height="29" valign="top"
				background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/left-top-right.gif" width="17" height="29" /></td>
			<td width="" height="29" valign="top"
				background="${ctx}/images/content-bg.gif"><table width="100%"
					height="31" border="0" cellpadding="0" cellspacing="0"
					class="left_topbg" id="table2">
					<tr>
						<td height="31"><div class="titlebt">特权管理</div></td>
					</tr>
				</table></td>
			<td width="16" valign="top"
				background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/nav-right-bg.gif" width="16" height="29" /></td>
		</tr>
		<tr>
			<td height="71" valign="middle"
				background="${ctx}/images/mail_leftbg.gif">&nbsp;</td>
			<td valign="top" bgcolor="#F7F8F9"><table width="100%"
					height="138" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="13" valign="top">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top"><table width="98%" border="0" align="center"
								cellpadding="0" cellspacing="0">
								<tr>
									<td class="left_txt">当前位置：特权管理</td>
								</tr>
								<tr>
									<td height="20"><table width="100%" height="1" border="0"
											cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
											<tr>
												<td></td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td height="20">
										<table width="100%" height="31" border="0"
											cellpadding="0" cellspacing="0" class="nowtable">
											<tr>
												<td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="queryModules()">添加特权</a></td>
											</tr>
										</table>
									</td>
								</tr>
								<tr id="addDiv" style="display: none;">
									<td height="50">
										<div  class="left_txt2">
											&nbsp;&nbsp;&nbsp;&nbsp;
											<select id="models"></select>
											特权名称：<input type="text" id="rivilegesName"/>
											特权URL：<input type="text" id="privUrl"/>
											IsTree:
											<input type="checkbox" id="isTree"/>
											<input type="button" onclick="addrivileges()" value="确定"/>
										</div>
									</td>
								</tr>
								<tr>
									<td><table width="100%" height="31" border="0"
											cellpadding="0" cellspacing="0" class="nowtable">
											<tr>
												<td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;审批记录</td>
											</tr>
										</table></td>
								</tr>
								<tr>
									<td width="100%" valign="top"
										style="min-height: 350px; height: 350px;">
										<table class="tblExcel" cellpadding="0" cellspacing="0">
											<thead>
												<tr>
												<td height="30" width="5%" class="left_txt2" align="center">序号</td>
												<td height="30" width="7%" class="left_txt2" align="center">名子</td>
												<td height="30" width="13%" class="left_txt2" align="center">URL</td>
												</tr>
											</thead>
											<tbody id="staffs">
												
											</tbody>
										</table>
										<div id="demo1"></div>
									</td>
								</tr>
							</table></td>
					</tr>
				</table></td>
			<td background="${ctx}/images/mail_rightbg.gif">&nbsp;</td>
		</tr>
		<tr>
			<td valign="middle" background="${ctx}/images/mail_leftbg.gif"><img
				src="${ctx}/images/buttom_left2.gif" width="17" height="17" /></td>
			<td height="17" valign="top"
				background="${ctx}/images/buttom_bgs.gif"><img
				src="${ctx}/images/buttom_bgs.gif" width="17" height="17" /></td>
			<td background="${ctx}/images/mail_rightbg.gif"><img
				src="${ctx}/images/buttom_right2.gif" width="16" height="17" /></td>
		</tr>
	</table>
</body>
</html>